﻿/**
 *
 * @title: Basic MVC Framework, View Class
 * @author: 
 * @license: 
 * @updated: 29/07/2010
 *
 * @version	1.0 
 */

package com.mediagallary.utils {
	
	import gs.TweenLite;
	
	import flash.display.*;
	import flash.events.Event;
	import flash.net.URLRequest;

	import flash.filters.DropShadowFilter;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.display.Sprite;
	
	/**
	 * Basic View class in Model/View/Controller triad.
	 */
	public class ImageLoader extends Sprite{
		
		private var loader:Loader;
		private var bmp:Bitmap;
		private var thumbContainer:Sprite;
		
		// store a reference to the _controller:
		//private var _controller:GallaryController;
		
		private var stageWidth:Number = 580;
		private var stageHeight:Number = 520;

		// we will only allow the user to getNext/Prev image if we 
		// are not currentlyanimating a transition between 2 images:
		private var isAnimating:Boolean;
		
		public function ImageLoader() {
		
			thumbContainer = new Sprite();
			thumbContainer.buttonMode = true;
			bmp = new Bitmap();
			loader = new Loader();
			thumbContainer.addChild(bmp);
			thumbContainer.addChild(loader);
			addChild(thumbContainer);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
		} 
		
		public function loadImage(path:String):void
		{
			trace("ImageLoader loadImage loader : "+loader.width);
			if(loader.width > 0)
			{
				trace("ImageLoader loadImage IF: ");
				thumbContainer.addChild(bmp);
				bmp.alpha = 1;
				bmp.x = loader.x;
				bmp.y = loader.y;
				bmp.bitmapData = new BitmapData(loader.content.width, loader.content.height);
				bmp.bitmapData.draw(loader);

			}
			//trace("ImageLoader loadImage path : "+path);
			loader.load(new URLRequest(path));
			
			//trace("IMAGE URL : " );
		}
		
		private function imageLoaded(event:Event):void
		{
			trace("ImageLoader imageLoaded : "+event.target+", loader.width : "+loader.width+", loader.visible : "+loader.visible);
			
			/*var myDropShadowFilter:DropShadowFilter = new DropShadowFilter (12,45,0x000000,0.5,10,10,1,2,false,false,false);
			thumbContainer.filters = [myDropShadowFilter];*/
			thumbContainer.addChild(loader);
			
			/*loader.x = (stageWidth / 2) - (loader.width / 2);
		  	loader.y = (stageHeight / 2) - (loader.height / 2) -30;*/
			loader.width = 200;
			loader.height = 100;
			//loader.alpha = 0;
			/*TweenLite.to(loader,0.7,{alpha:1,onStart:onTweenStart, onComplete:onTweenComplete});
			TweenLite.to(bmp, 0.7, {alpha:0});*/
		}
		
		/*public function getIsAnimating():Boolean
		{
			return isAnimating;
		}
		
		// set a flag that will allow us to ignore user input while 
		// an animation is in progress
		private function onTweenStart():void
		{
			isAnimating = true;
		}
		
		private function onTweenComplete():void
		{
			isAnimating = false;
		}*/
		
	}
}